﻿using System;
using System.IO;

namespace YYFIndexNow
{
    /// <summary>
    /// 写文件
    /// </summary>
    public static class WriteHelper
    {
        public static void WriteLog(string content, string filename = "", string directory = "log", string ext = "log", string rootdir = null)
        {
            string dir = AppDomain.CurrentDomain.BaseDirectory + directory;
            if (!string.IsNullOrWhiteSpace(rootdir))
            {
                if (!rootdir.EndsWith("/"))
                {
                    rootdir = rootdir + "/";
                }
                dir = rootdir + directory;
            }
            if (!System.IO.Directory.Exists(dir))
            {
                System.IO.Directory.CreateDirectory(dir);
            }
            string filepath = Path.Combine(dir, $"{filename}.{ext}");
            using (var sw = File.AppendText(filepath))
            {
                sw.WriteLine(content);
            }
        }
    }
}
